# cmake最低版本要求
cmake_minimum_required(VERSION 3.13)

project(redis-7.0.4)

#debug模式编译
set(CMAKE_BUILD_TYPE Debug CACHE STRING "set build type to debug")


#可执行文件的输出目录
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/output/)

#安装路径
set(CMAKE_INSTALL_PREFIX ${PROJECT_SOURCE_DIR}/output/target/)

#依赖库目录
#Redis源码编译需要依赖的自定义库的路径，在主目录deps下
set(DEPS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/deps)

#依赖库目录
#Redis源码编译需要依赖的自定义库的路径，在主目录deps下
set(DEPS_PATH ${CMAKE_CURRENT_SOURCE_DIR}/deps)

#依赖共享库, 根据原Rerdis中的Makefile，编译源码需要依赖的系统共享库
set(SHARED_LIBS -lm -ldl -lpthread)

#在编译Redis之前需要执行src目录下的 mkreleasehdr.sh 脚本生成 release.h
execute_process(COMMAND sh ${CMAKE_CURRENT_SOURCE_DIR}/src/mkreleasehdr.sh WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/src)

#include directories
include_directories(
        ${DEPS_PATH}/hdr_histogram
        ${DEPS_PATH}/hiredis
        ${DEPS_PATH}/lua/src
        ${DEPS_PATH}/linenoise
)

# 添加需要编译子目录
add_subdirectory(deps)
# # 添加链接器搜索路径()
# link_directories(${DEPS_PATH}/hdr_histogram)
# link_directories(${DEPS_PATH}/hiredis)
# link_directories(${DEPS_PATH}/lua/src)
# link_directories(${DEPS_PATH}/linenoise)

set(REDIS_SERVER_LIST src/adlist.c src/quicklist.c src/ae.c src/anet.c src/dict.c src/server.c src/sds.c src/zmalloc.c src/lzf_c.c src/lzf_d.c src/pqsort.c src/zipmap.c src/sha1.c src/ziplist.c src/release.c src/networking.c src/util.c src/object.c src/db.c src/replication.c src/rdb.c src/t_string.c src/t_list.c src/t_set.c src/t_zset.c src/t_hash.c src/config.c src/aof.c src/pubsub.c src/multi.c src/debug.c src/sort.c src/intset.c src/syncio.c src/cluster.c src/crc16.c src/endianconv.c src/slowlog.c src/eval.c src/bio.c src/rio.c src/rand.c src/memtest.c src/syscheck.c src/crcspeed.c src/crc64.c src/bitops.c src/sentinel.c src/notify.c src/setproctitle.c src/blocked.c src/hyperloglog.c src/latency.c src/sparkline.c src/redis-check-rdb.c src/redis-check-aof.c src/geo.c src/lazyfree.c src/module.c src/evict.c src/expire.c src/geohash.c src/geohash_helper.c src/childinfo.c src/defrag.c src/siphash.c src/rax.c src/t_stream.c src/listpack.c src/localtime.c src/lolwut.c src/lolwut5.c src/lolwut6.c src/acl.c src/tracking.c src/connection.c src/tls.c src/sha256.c src/timeout.c src/setcpuaffinity.c src/monotonic.c src/mt19937-64.c src/resp_parser.c src/call_reply.c src/script_lua.c src/script.c src/functions.c src/function_lua.c src/commands.c)
#生成可执行文件
add_executable(redis-server ${REDIS_SERVER_LIST})

# 将目标文件与库文件进行链接
target_link_libraries(redis-server hdr_histogram hiredis lua ${SHARED_LIBS})



#执行make install执行以下安装程序
install(TARGETS redis-server DESTINATION bin)